#ifndef _LIB_XML2_XML_IMPL_H
#define _LIB_XML2_XML_IMPL_H

#include "XmlDef.h"
#include <libxml/tree.h>

XML_TOOL_NAMESPACE_BEGIN

class LibXml2XmlFactory;
class LibXml2XmlDocument;

class LibXml2XmlNode : public XmlNode
{
	friend class LibXml2XmlFactory;
	friend class LibXml2XmlDocument;

public:
	virtual bool GetAttribute(const string& attrName, string& attrValue) const;
	virtual void SetAttribute(const string& attrName, const string& attrValue);
	virtual XmlNodePtr GetParent() const;
	virtual XmlNodePtr GetFirstChild() const;
	virtual XmlNodePtr GetLastChild() const;
	virtual XmlNodePtr GetNextSibling() const;
	virtual XmlNodePtr GetPrevSibling() const;
	virtual const XmlDocumentPtr GetDocument() const;
	virtual string GetNodeName() const;
	virtual string GetTextContent() const;
	virtual XmlNodeType GetNodeType() const;
	virtual void AppendChild(XmlNodePtr childNode);
	virtual string BindToXmlText(const string& encoding);

protected:
	LibXml2XmlNode(const LibXml2XmlDocument* doc, LibXml2XmlNode* parent, xmlNodePtr node);
	virtual ~LibXml2XmlNode();

	//LibXml2XmlNode* GetMemberNode(xmlNodePtr xmlNode::* xmlNodeMember, 
	//								LibXml2XmlNode* LibXml2XmlNode::* thisMember);

	void Release();
private:
	xmlNodePtr mNode;
	const LibXml2XmlDocument* mDoc;
	LibXml2XmlNode* mParent;
	LibXml2XmlNode* mFirstChild;
	LibXml2XmlNode* mLastChild;
	LibXml2XmlNode* mNextSibling;
	LibXml2XmlNode* mPrevSibling;
};

class LibXml2XmlDocument : public XmlDocument
{
	friend class LibXml2XmlFactory;
	friend class LibXml2XmlNode;

public:
	virtual XmlNodePtr GetDocumentRoot() const;
	virtual void SetDocumentRoot(XmlNodePtr xmlNode);
	virtual XmlNodePtr CreateXmlNode(const string& nodeName);
	virtual XmlNodePtr CreateTextNode(const string& nodeName, const string& nodeValue);
	virtual void ReleaseXmlNode(XmlNodePtr xmlNode);
	virtual string BindToXmlText(const string& encoding);

protected:
	LibXml2XmlDocument(xmlDocPtr doc);
	virtual ~LibXml2XmlDocument();

	static LibXml2XmlDocument* CreateDocument();
	static LibXml2XmlDocument* CreateDocument(const string& xmlText, const string& encoding);

private:
	xmlDocPtr mDoc;
	LibXml2XmlNode* mRootNode;
};

XML_TOOL_NAMESPACE_END

#endif //_LIB_XML2_XML_IMPL_H